@(target: String,
  issues: List[(gitbucket.core.service.IssuesService.IssueInfo, Option[(gitbucket.core.model.CommitState, List[gitbucket.core.model.CommitStatus])])],
  page: Int,
  openCount: Int,
  closedCount: Int,
  condition: gitbucket.core.service.IssuesService.IssueSearchCondition,
  collaborators: List[String] = Nil,
  milestones: List[gitbucket.core.model.Milestone] = Nil,
  priorities: List[gitbucket.core.model.Priority] = Nil,
  labels: List[gitbucket.core.model.Label] = Nil,
  repository: Option[gitbucket.core.service.RepositoryService.RepositoryInfo] = None,
  isManageable: Boolean = false)(implicit context: gitbucket.core.controller.Context)
@import gitbucket.core.view.helpers
@import gitbucket.core.service.IssuesService.IssueInfo
@*
@if(condition.nonEmpty){
  <div style="width: 100%; display: inline-block;">
    <a href="@gitbucket.core.service.IssuesService.IssueSearchCondition().toURL" class="header-link">
      <i class="octicon octicon-x" ></i>
      <span class="strong">Clear current search query, filters, and sorts</span>
    </a>
  </div>
}
*@
<table class="table table-bordered table-hover table-issues">
  <thead>
    <tr>
      <th style="background-color: #eee;">
        <input type="checkbox" aria-label="Select all issues"/>
        <span id="table-issues-control">
          @gitbucket.core.helper.html.dropdown("Author", filter = ("author", "Find Author...")) {
            @collaborators.map { collaborator =>
              <li>
                <a href="@condition.copy(author = (if(condition.author == Some(collaborator)) None else Some(collaborator))).toURL">
                  @gitbucket.core.helper.html.checkicon(condition.author == Some(collaborator))
                  @helpers.avatar(collaborator, 20) @collaborator
                </a>
              </li>
            }
          }
          @gitbucket.core.helper.html.dropdown("Label", filter = ("label", "Find Label...")) {
            @labels.map { label =>
              <li>
                <a href="@condition.copy(labels = (if(condition.labels.contains(label.labelName)) condition.labels - label.labelName else condition.labels + label.labelName)).toURL">
                  @gitbucket.core.helper.html.checkicon(condition.labels.contains(label.labelName))
                  <span style="background-color: #@label.color;" class="label-color">&nbsp;&nbsp;</span>
                  @label.labelName
                </a>
              </li>
            }
          }
          @gitbucket.core.helper.html.dropdown("Priority", filter = ("priority", "Find Priority...")) {
            <li>
              <a href="@condition.copy(priority = (if(condition.priority == Some(None)) None else Some(None))).toURL">
                @gitbucket.core.helper.html.checkicon(condition.priority == Some(None)) Issues with no priority
              </a>
            </li>
            @priorities.map { priority =>
              <li>
                <a href="@condition.copy(priority = (if(condition.priority == Some(Some(priority.priorityName))) None else Some(Some(priority.priorityName)))).toURL"@if(!priority.description.isEmpty) { title="@priority.description.get" }>
                  @gitbucket.core.helper.html.checkicon(condition.priority == Some(Some(priority.priorityName)))
                  <span style="background-color: #@priority.color;" class="label-color">&nbsp;&nbsp;</span>
                  @priority.priorityName
                </a>
              </li>
            }
          }
          @gitbucket.core.helper.html.dropdown("Milestone", filter = ("milestone", "Find Milestone...")) {
            <li>
              <a href="@condition.copy(milestone = (if(condition.milestone == Some(None)) None else Some(None))).toURL">
                @gitbucket.core.helper.html.checkicon(condition.milestone == Some(None)) Issues with no milestone
              </a>
            </li>
            @milestones.filter(_.closedDate.isEmpty).map { milestone =>
              <li>
                <a href="@condition.copy(milestone = (if(condition.milestone == Some(Some(milestone.title))) None else Some(Some(milestone.title)))).toURL">
                  @gitbucket.core.helper.html.checkicon(condition.milestone == Some(Some(milestone.title))) @milestone.title
                </a>
              </li>
            }
          }
          @gitbucket.core.helper.html.dropdown("Assignee", filter = ("assignee", "Find Assignee...")) {
            <li>
              <a href="@condition.copy(assigned = (if(condition.assigned == Some(None)) None else Some(None))).toURL">
                @gitbucket.core.helper.html.checkicon(condition.assigned == Some(None)) Assigned to nobody
              </a>
            </li>
            @collaborators.map { collaborator =>
              <li>
                <a href="@condition.copy(assigned = (if(condition.assigned == Some(Some(collaborator))) None else Some(Some(collaborator)))).toURL">
                  @gitbucket.core.helper.html.checkicon(condition.assigned == Some(Some(collaborator)))
                  @helpers.avatar(collaborator, 20) @collaborator
                </a>
              </li>
            }
          }
          @gitbucket.core.helper.html.dropdown("Sort"){
            <li>
              <a href="@condition.copy(sort="created",  direction="desc").toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "created"  && condition.direction == "desc") Newest
              </a>
            </li>
            <li>
              <a href="@condition.copy(sort="created",  direction="asc" ).toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "created"  && condition.direction == "asc") Oldest
              </a>
            </li>
            <li>
              <a href="@condition.copy(sort="priority", direction="asc").toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "priority"  && condition.direction == "asc") Highest priority
              </a>
            </li>
            <li>
              <a href="@condition.copy(sort="priority", direction="desc" ).toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "priority"  && condition.direction == "desc") Lowest priority
              </a>
            </li>
            <li>
              <a href="@condition.copy(sort="comments", direction="desc").toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "comments"  && condition.direction == "desc") Most commented
              </a>
            </li>
            <li>
              <a href="@condition.copy(sort="comments", direction="asc" ).toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "comments"  && condition.direction == "asc") Least commented
              </a>
            </li>
            <li>
              <a href="@condition.copy(sort="updated",  direction="desc").toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "updated"  && condition.direction == "desc") Recently updated
              </a>
            </li>
            <li>
              <a href="@condition.copy(sort="updated",  direction="asc" ).toURL">
                @gitbucket.core.helper.html.checkicon(condition.sort == "updated"  && condition.direction == "asc") Least recently updated
              </a>
            </li>
          }
        </span>
        @if(isManageable){
          <span id="table-issues-batchedit">
            @gitbucket.core.helper.html.dropdown("Mark as") {
              <li><a href="javascript:void(0);" class="toggle-state" data-id="open">Open</a></li>
              <li><a href="javascript:void(0);" class="toggle-state" data-id="close">Close</a></li>
            }
            @gitbucket.core.helper.html.dropdown("Label", filter = ("label", "Find Label...")) {
              @labels.map { label =>
                <li>
                  <a href="javascript:void(0);" class="toggle-label" data-id="@label.labelId">
                    <i class="octicon"></i>
                    <span class="label" style="background-color: #@label.color;">&nbsp;</span>
                    @label.labelName
                  </a>
                </li>
              }
            }
            @gitbucket.core.helper.html.dropdown("Priority", filter = ("priority", "Find Priority...")) {
              <li><a href="javascript:void(0);" class="toggle-priority" data-id="">No priority</a></li>
              @priorities.map { priority =>
                <li><a href="javascript:void(0);" class="toggle-priority" data-id="@priority.priorityId"@if(!priority.description.isEmpty) { title="@priority.description.get" }>
                  <span style="background-color: #@priority.color;" class="label">&nbsp;</span>
                  @priority.priorityName</a></li>
              }
            }
            @gitbucket.core.helper.html.dropdown("Milestone", filter = ("milestone", "Find Milestone...")) {
              <li><a href="javascript:void(0);" class="toggle-milestone" data-id="">No milestone</a></li>
              @milestones.filter(_.closedDate.isEmpty).map { milestone =>
                <li><a href="javascript:void(0);" class="toggle-milestone" data-id="@milestone.milestoneId">@milestone.title</a></li>
              }
            }
            @gitbucket.core.helper.html.dropdown("Assignee", filter = ("assignee", "Find Assignee...")) {
              <li><a href="javascript:void(0);" class="toggle-assign" data-name=""><i class="octicon octicon-x"></i> Clear assignee</a></li>
              @collaborators.map { collaborator =>
                <li><a href="javascript:void(0);" class="toggle-assign" data-name="@collaborator"><i class="octicon"></i>@helpers.avatar(collaborator, 20) @collaborator</a></li>
              }
            }
          </span>
        }
      </th>
    </tr>
  </thead>
  <tbody>
    @if(issues.isEmpty){
      <tr>
        <td style="padding: 20px; background-color: #eee; text-align: center;">
          @if(target == "issues"){
            No issues to show.
          } else {
            No pull requests to show.
          }
          @*
          @if(condition.labels.nonEmpty || condition.milestone.isDefined){
            <a href="@condition.copy(labels = Set.empty, milestone = None).toURL">Clear active filters.</a>
          } else {
          *@
            @if(repository.isDefined){
              @if(target == "issues"){
                <a href="@helpers.url(repository.get)/issues/new">Create a new issue.</a>
              } else {
                <a href="@helpers.url(repository.get)/compare">Create a new pull request.</a>
              }
            }
          @*
          }
          *@
        </td>
      </tr>
    }
    @issues.map { case (IssueInfo(issue, labels, milestone, priority, commentCount, commitId, assignedUserNames), status) =>
      <tr>
        <td style="padding-top: 12px; padding-bottom: 12px;">
          @if(isManageable){
            <input type="checkbox" value="@issue.issueId" aria-labelledby="issue_@(issue.issueId)_link"/>
          }
          @*
          <i class="octicon octicon-issue-@(if(issue.closed) "closed" else "opened")" style="margin-right: 3px;"></i>
          *@
          @if(repository.isEmpty){
            <a href="@context.path/@issue.userName/@issue.repositoryName">@issue.repositoryName</a>&nbsp;&#xFF65;
          }
          @if(target == "issues"){
            <a id="issue_@(issue.issueId)_link" href="@context.path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-title">@issue.title</a>
          } else {
            <a id="issue_@(issue.issueId)_link" href="@context.path/@issue.userName/@issue.repositoryName/pull/@issue.issueId" class="issue-title">@issue.title</a>
          }
          @status.map { case (summary, statuses) =>
            @gitbucket.core.helper.html.commitstatus(commitId.get, summary, statuses)
          }
          @labels.map { label =>
            <span class="label-color small" style="background-color: #@label.color; color: #@label.fontColor; padding-left: 4px; padding-right: 4px">@label.labelName</span>
          }
          <span class="pull-right small">
            @assignedUserNames.map { userName =>
              @helpers.avatar(userName, 20, tooltip = true)
            }
            @if(commentCount > 0){
              <a href="@context.path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count">
                <i class="octicon octicon-comment active"></i> @commentCount
              </a>
            } else {
              <a href="@context.path/@issue.userName/@issue.repositoryName/issues/@issue.issueId" class="issue-comment-count" style="color: silver;">
                <i class="octicon octicon-comment"></i> @commentCount
              </a>
            }
          </span>
          <div class="small muted" style="margin-left: 12px; margin-top: 2px;">
            #@issue.issueId opened @gitbucket.core.helper.html.datetimeago(issue.registeredDate) by @helpers.user(issue.openedUserName, styleClass="username")
            @priority.map(priority => priorities.filter(p => p.priorityName == priority).head).map { priority =>
            <span style="margin: 20px;"><a href="@condition.copy(priority = Some(Some(priority.priorityName))).toURL" class="username"@if(!priority.description.isEmpty) { title="@priority.description.get" }><i class="octicon octicon-flame"></i>
              <span class="issue-priority issue-priority-inline" style="background-color: #@priority.color; color: #@priority.fontColor;">@priority.priorityName</span></a></span>
            }
            @milestone.map { milestone =>
              <span style="margin: 20px;"><a href="@condition.copy(milestone = Some(Some(milestone))).toURL" class="username"><i class="octicon octicon-milestone"></i> @milestone</a></span>
            }
          </div>
        </td>
      </tr>
    }
  </tbody>
</table>
<div class="pull-right">
  @gitbucket.core.helper.html.paginator(page, (if(condition.state == "open") openCount else closedCount), gitbucket.core.service.IssuesService.IssueLimit, 10, condition.toURL)
</div>
